<?php

namespace app\controller;
use app\model\CountryModel;
use Exception;
use think\annotation\Route;
use think\facade\Db;
use think\response\Json;

class CountryController
{
    /**
     * 插入给定的所有国家
     * @param CountryModel $cM
     * @return Json
     * @throws Exception
     * @route ("insertCountries")
     * @var array $countries
     */
    public function insertCountries(array $countries, CountryModel $cM): Json
    {
        return json($cM->insertCountries($countries));
    }


    /**
     * 查询所有国家信息
     * @route ("selectAllCountries")
     * @param CountryModel $countryModel
     * @return Json
     */
    public function selectAllCountries(CountryModel $countryModel): Json
    {
        return json($countryModel->selectAllCountries());
    }

    /**
     * 更具给定的国家id查找国家信息
     * @route ("selectCountriesById")
     * @param array $ids
     * @param CountryModel $countryModel
     * @return Json
     */
    public function selectCountriesById(array $ids, CountryModel $countryModel): Json
    {
        return json($countryModel->selectCountriesById($ids));
    }

    /**
     * 根据国家id修改信息
     * @route ("updateThisCountry")
     * @param $des
     * @param CountryModel $countryModel
     * @return void
     */
    public function updateThisCountry($des, CountryModel $countryModel)
    {
        $countryModel->updateThisCountry($des);
        //echo Db::getLastSql();
    }


    /**
     * @route ("deleteCountriesById")
     * @param $countriesId
     * @param CountryModel $countryModel
     * @return Json
     */
    public function deleteCountriesById($countriesId, CountryModel $countryModel): Json
    {
        return json(["result"=>$countryModel->deleteCountriesById($countriesId)]);
    }

}